% matlab < /Users/woolrich/homedir/matlab/osl1.2.beta.15/osl_test_script.m > /Users/woolrich/homedir/matlab/osl_testdata_dir/test_output/log.txt 2>&1 &
% tail -f /Users/woolrich/homedir/matlab/osl_testdata_dir/test_output/log.txt

% matlab < /home/mwoolrich/homedir/matlab/osl1.2.beta.15/osl_test_script.m > /home/disk3/mwoolrich/vols_data/osl_testdata_dir/test_output/log_oil.txt 2>&1 &
% tail -f /home/disk3/mwoolrich/vols_data/osl_testdata_dir/test_output/log_oil.txt

tilde='/Users/woolrich';
tilde='/home/mwoolrich';

osldir=[tilde '/homedir/matlab/osl1.2.beta.17'];
global OSLDIR;
addpath(osldir);
osl_startup(osldir);

testdatadir=[tilde '/homedir/matlab/osl_testdata_dir'];
%testdatadir=['/home/disk3/mwoolrich/vols_data/osl_testdata_dir'];

testoutputdir=[testdatadir '/test_output'];

%%

if(0)
    S=[];
    S.recon_method='beamform';S.forward_meg='Single Shell';S.work_in_pca_subspace=1;S.do_hmm=0;
    osl_test_script_recon(testdatadir,testoutputdir,S);
    S.recon_method='beamform';S.forward_meg='MEG Local Spheres';S.work_in_pca_subspace=0;S.do_hmm=0;
    osl_test_script_recon(testdatadir,testoutputdir,S);
    S.recon_method='beamform';S.forward_meg='Single Shell';S.work_in_pca_subspace=1;S.do_hmm=1;
    osl_test_script_recon(testdatadir,testoutputdir,S);
    S.recon_method='beamform';S.forward_meg='MEG Local Spheres';S.work_in_pca_subspace=0;S.do_hmm=1;
    osl_test_script_recon(testdatadir,testoutputdir,S);
end;


osl_test_script_sensorspace(testdatadir,testoutputdir,S);
osl_test_script_group(testdatadir,testoutputdir,S);

%S.recon_method='beamform';S.forward_meg='MEG Local Spheres';S.work_in_pca_subspace=0;S.do_hmm=0;
%osl_test_script_oil(testdatadir,testoutputdir,S);

if(0),
    S=[];
    S.do_sss=0;S.recon_method='beamform';S.forward_meg='MEG Local Spheres';S.work_in_pca_subspace=0;S.do_hmm=0;
    testoutputdir_full=osl_test_script_group_full(testdatadir,testoutputdir,S);

    S=[];
    S.do_sss=0;S.recon_method='beamform';S.forward_meg='MEG Local Spheres';S.work_in_pca_subspace=0;S.do_hmm=1;
    testoutputdir_full=osl_test_script_group_full(testdatadir,testoutputdir,S);

    S=[];
    S.do_sss=1;S.recon_method='beamform';S.forward_meg='MEG Local Spheres';S.work_in_pca_subspace=0;S.do_hmm=0;
    testoutputdir_full=osl_test_script_group_full(testdatadir,testoutputdir,S);

    S=[];
    S.do_sss=1;S.recon_method='beamform';S.forward_meg='MEG Local Spheres';S.work_in_pca_subspace=0;S.do_hmm=1;
    testoutputdir_full=osl_test_script_group_full(testdatadir,testoutputdir,S);

    S=[];
    S.do_sss=0;S.recon_method='mne';S.forward_meg='MEG Local Spheres';S.work_in_pca_subspace=0;S.do_hmm=0;
    testoutputdir_full=osl_test_script_group_full(testdatadir,testoutputdir,S);

    S=[];
    S.do_sss=1;S.recon_method='mne';S.forward_meg='MEG Local Spheres';S.work_in_pca_subspace=0;S.do_hmm=1;
    testoutputdir_full=osl_test_script_group_full(testdatadir,testoutputdir,S);
end;

if(0)
    S=[];
    S.do_sss=0;S.recon_method='beamform';S.forward_meg='Single Shell';S.work_in_pca_subspace=0;S.do_hmm=0;
    
    %%
    hmm_av_class_occupancy=20;
    testoutputdir_full=[testoutputdir '/script_group_full_hmmav' num2str(hmm_av_class_occupancy) '_' regexprep(S.forward_meg, ' ', '') '_hmm' num2str(S.do_hmm) '_' S.recon_method '_sss' num2str(S.do_sss)];
    if(1)
        printprefix='group_oat';
        oat.source_recon.dirname=[testoutputdir_full '/' printprefix];
        oat=osl_load_oat(oat.source_recon.dirname);


        S2=[];
        S2.oat=oat;
        S2.stats_fname=oat.group_level.results_fnames;
        S2.first_level_contrasts=[5]; % list of first level contrasts to output
        [statsdir,times]=osl_save_nii_stats(S2);
    end;

    for con=1:5,
        runcmd(['cp ' testoutputdir_full '/group_oat.oat/first_level_sub_level_group_level_dir/tstat' num2str(con) '_gc1_2mm.nii.gz ' testdatadir '/tstat' num2str(con) '_full_' regexprep(S.forward_meg, ' ', '') '_hmm' num2str(S.do_hmm) '_' S.recon_method '_sss' num2str(S.do_sss) '.nii.gz']);
    end;
    %%
end;